// 微信小程序中必须使用App()函数进行微信小程序的注册
App({
    onLaunch: function () {
        // 调用API从本地缓存中获取数据
        var logs = wx.getStorageSync('logs') || []
        logs.unshift(Date.now())
        wx.setStorageSync('logs', logs)
    },
    getUserInfo: function (ob) {
        var that = this;
        if (this.globalData.userInfo) {
            typeof ob == "function" && ob(this.globalData.userInfo)
        } else {
            // 调用登录接口
            wx.login({
                success: function () {
                    wx.getUserInfo({
                        success: function (res) {
                            that.globalData.userInfo = res.userInfo;
                            typeof ob == "function" && ob(that.globalData.userInfo)
                        }
                    })
                }
            })
        }
    },
    globalData: {
        userInfo: null
    }
})